Release 10.1A: OpenEdge Development:
ProDataSets
Building a business entity procedure to support the ProDataSet
Next, you’ll write the procedure that really represents the
dsOrderProDataSet itself. This is a variation of theOrderSupport.pprocedure you’ve written before. Call itOrderEntity.p.The goal of this part of the exercise is to create a business entity object that manages
dsOrder, expanding on the data access procedure you created earlier. Figure 10–2 is a sketch of the larger entity object.Figure 10–2: Business entity procedure
![]()
The data access object becomes part of a larger
Orderentity or business object. The entity presents an API to the outside world that supports specific types of access to the object. Any requests that need to fill or save data use the business entity procedure as a gateway to the data managed in the data access object.Validation logic for saving changes and other business logic associated with the ProDataSet are also encapsulated within the entity so that the logic is always executed consistently whenever the ProDataSet is referenced. Now you are working with a true business object.
Procedure
OrderEntity.pis a simple example of the business entity procedure. It manages the API the client window uses to test the procedures and coordinate access to the data. Later, you’ll attach validation logic to it as well.There isn’t very much code in the procedure, partly because some of it is in
OrderSource.pand partly because some of it will be moved to a new general purpose dynamic procedure to handle the whole save-changes process.This is the procedure that actually “owns” the ProDataSet instance on the server side. It is this procedure’s ProDataSet instance that the
FILLevents and the Data-Sources are attached to, and this instance that is actually filled with data to be passed back to the client.
OrderEntity.pwill be runPERSISTENTin support of the client window, as a server side procedure, either locally in the client process or remotely. It first gets the handle of the ProDataSet and uses this to set up aCLOSEtrigger for the procedure to clean up, as shown:
Remember that you cannot obtain a handle such as
hDataSetin the procedure main block and then use it inside internal procedures that have a ProDataSet as a parameter passedBY-REFERENCE. The handle won’t be valid in those procedures because they are pointing to the external ProDataSet instance. This code gets the handle at the top of the main block simply because there is a limitation in theDYNAMIC-FUNCTIONsyntax that does not recognize the formDATASET dsOrder:HANDLEas a parameter. (This is actually the same restriction that already exists forBUFFERhandle references.) Thus, you need to obtain the handle in advance so that you can simply name the handle variable in the function reference.Next, the main block starts the data access procedure and runs the
attachDataSetfunction for the local ProDataSet instance:
Because the methods in
OrderSource.poperate on the ProDataSet instance passed into it, a single instance of the procedure itself could support any number of external instances of the ProDataSet. Therefore, in your application you could check whether there is already a running instance of a procedure such as this and use its handle if there is.Remember that the
fetchOrderprocedure inOrderSource.pis intended to be called from its enclosing business entity procedure. Following is the version offetchOrderthat a procedure outside theOrderentity calls to get anOrderback. It defines its ownOUTPUTparameter explicitlyBY-VALUEto assure that no other procedure tries to pass in another ProDataSet instanceBY-REFERENCE. This is because it is the instance inOrderEntity.pthat has been attached to theFILLevents and Data-Sources, and only that instance can be filled properly.Procedure
fetchOrderturns around and passes in theOrderNumber value tofetchOrderinOrderSource.p, along with its own ProDataSet instanceBY-REFERENCE. In this way, it makes sure the local instance is used. For example:
Finally, there is a
saveChangesprocedure inOrderEntity.p. This attaches the Data-Sources to make sure they are there for the save, and then runs a new procedure that you’ll write next, which captures all the standard save logic in a single dynamic procedure. It then detaches the Data-Sources from the ProDataSet, as shown:
As you can see,
saveChangesis actually entirely generic. It could operate on any ProDataSet, as long as it knows the procedure handle of the data access procedure that’s stored inhSourceProc. If you had a generic session manager that coordinated running procedures on the server, your client could simply runsaveChangesin that session manager, which could use the ProDataSet parameter to identify the ProDataSet type or name (dsOrderin this case), and sethSourceProcto the data access procedure for that ProDataSet. Since our simple example doesn’t have such a manager, we putsaveChangesinto theOrderentity itself.This is the end of the code for
OrderEntity.p.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |